package circuit1;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author Erik
 */

import java.util.Observer;
import java.util.Observable;
import java.util.ArrayList;

public class StabilityObserver implements Observer {

    int count;
    boolean isChange;
    boolean isStable;

    public StabilityObserver() {

        count = 0;
        isChange = false;
        isStable = false;
    }

    public void update(Observable o, Object arg) {
        reset();
        Integer count = (Integer) arg;
        isChange = true;
    }

    public void reset() {
    
        count = 0;
        isChange = false;
        isStable = false;
    }

    public boolean count() {
        if (isChange) {
            reset();
        } else {
            count++;
            if (count >= 10) {
            ////System.out.println("A kor stabil");
            isStable = true;
            }
        }
        return isStable;
    }

    public void prodAllElements(ArrayList<IElement> elements) {
        for (int j = 0; j < elements.size(); j++) {
            ////System.out.println(elements.get(j).getId());
            ////System.out.println("prod: " + elements.get(j).getId());
            ////System.out.println("-------- PROD ELOTT: " + elements.get(j).getId() + " " + elements.get(j).getOut());
            elements.get(j).prod();
            ////System.out.println("-------- PROD UTAN: " + elements.get(j).getId() + " " + elements.get(j).getOut());
        }
        for (int j = 0; j < elements.size(); j++) {
            ////System.out.println(elements.get(j).getId());
            ////System.out.println("prod: " + elements.get(j).getId());
            //System.out.println("-------- PROD ELOTT: " + elements.get(j).getId() + " " + elements.get(j).getOut());
            //elements.get(j).prod();
            //System.out.println("-------- PROD UTAN: " + elements.get(j).getId() + " " + elements.get(j).getOut());
            //System.out.println();
        }
    }

    public void eval() {
        if (isStable) {
            //System.out.println("Circuit is stable");
            reset();
        } else {
            //System.out.println("Circuit is unstable");
        }
        
    }
}